package com.jule.miaozhuapc.filter;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Service;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.jule.miaozhuapc.service.UserService;

@Configuration  
@EnableWebMvc  
@ComponentScan(basePackages = "com.jule.miaozhuapc")  
@PropertySource(value = "classpath:application.properties",  
        ignoreResourceNotFound = true,encoding = "UTF-8")  
@Service
public class MvcConfig extends WebMvcConfigurerAdapter {  
    private static final Logger logger = Logger.getLogger(MvcConfig.class);

//    @Autowired
//    LoginInterceptor loginInterceptor;
  
//    @Autowired
//    public static UserService userService;
    /**
     * 拦截器配置 
     * @param registry 
     */  
    @Override  
    public void addInterceptors(InterceptorRegistry registry) {
        super.addInterceptors(registry);

        // 注册监控拦截器  
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/v1/**")
                .excludePathPatterns("/**.html");  //排除地址
    }
    
    /**
     *  自定义参数解析器
     */
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers)  {
        super.addArgumentResolvers(argumentResolvers);
        argumentResolvers.add(new TokenUserHandlerMethodArgumentResolver());
    }

    /**
     *  静态资源访问
     * @param registry
     */
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("/");
    }
}